const express = require("express")
const bodyParser = require("body-parser");

const post = 6061

const app = express()

//post中间件
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }));

// 用node服务器打开html文件 把所有的静态资源放在public文件夹下
app.use(express.static("./public"))

// 设置跨域
app.use(function(req,res,next){
    res.header("Access-Control-Allow-Origin","*")
    res.header("Access-Control-Allow-Headers","Content-Type,Content-Length,Authorization,Accept,X-Requested-With")
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS")
    next()
})

app.listen(post,function(){
    console.log("服务器已启动")
})

// 导出app
module.exports = app

